package com.shop2cn.iapi.sqdistributor.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sqdistributor.parameter.request.GetDistributorApplyListReq;
import com.shop2cn.iapi.sqdistributor.parameter.response.pojo.DistributorApplyVo;
import com.shop2cn.iapi.sqdistributor.service.GetDistributorApplyListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.sqdistributor.DistributorApply;
import com.ymttest.database.sqlwapper.sqdistributor.DistributorApplyWrapper;
import com.ymttest.utils.DataUtil;

public class Ts_GetDistributorApplyList {
	
	//java接口
	private static GetDistributorApplyListReq getDistributorApplyListReq;
	private static GetDistributorApplyListCall getDistributorApplyListCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取分销员申请列表");
	}

	@Before
	public void caseUp() {
		getDistributorApplyListReq = new GetDistributorApplyListReq();
		getDistributorApplyListCall = new GetDistributorApplyListCall();	
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getDistributorApplyListCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public void verifyDb() throws Exception {
		
		DistributorApplyWrapper distributorApplyWrapper = new DistributorApplyWrapper();
		
		List<DistributorApply> actualList = distributorApplyWrapper
				.selectByMerchantId(getDistributorApplyListReq.getMerchantId());
		List<DistributorApplyVo> expectList = getDistributorApplyListCall
				.getDistributorApplyListReponse().getDistributorApplyVoList();

		Logger.verifyEquals(expectList.size(), actualList.size(), "验证列表大小");
		
		for (int i = 0; i < expectList.size(); i++) {
			
			DistributorApply actualResult = actualList.get(i);
			DistributorApplyVo expectResult = expectList.get(i);
			
			Logger.verifyEquals(expectResult.getId(), actualResult.getId(),
					"验证Id");
			Logger.verifyEquals(expectResult.getMerchantId(), actualResult.getMerchant_id(),
					"验证Merchant_id");
			Logger.verifyEquals(expectResult.getApplyUserId(), actualResult.getApply_user_id(),
					"验证Apply_user_id");
			Logger.verifyEquals(expectResult.getApplyUserName(), actualResult.getApply_user_name(),
					"验证applyUserName");
			Logger.verifyEquals(expectResult.getApplyUserPhone(), actualResult.getApply_user_phone(),
					"验证applyUserPhone");
			Logger.verifyEquals(expectResult.getApplyUserPhone(), actualResult.getApply_user_phone(),
					"验证applyUserPhone");
			Logger.verifyEquals(expectResult.getReferrerId(), actualResult.getReferrer_id(),
					"验证referrerId");
			Logger.verifyEquals(expectResult.getReferrerName(), actualResult.getReferrer_name(),
					"验证referrerName");
			Logger.verifyEquals(expectResult.getAuditorId(), actualResult.getAuditor_id(),
					"验证auditorId");
			Logger.verifyEquals(expectResult.getAuditStatus(), actualResult.getAudit_status(),
					"验证auditStatus");
			DataUtil.verifyDateEquals(expectResult.getAuditTime(), actualResult.getAudit_time(),
					"验证auditTime");
			Logger.verifyEquals(expectResult.getAuditRemark(), actualResult.getAudit_remark(),
					"验证auditRemark");
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetDistributorApplyList_001() {
		Logger.start(true, "获取分销员申请列表, 查询多条数据");
		
		try {
			
			getDistributorApplyListReq.setMerchantId(500861041L);
//			getDistributorApplyListReq.setApplyUserName(applyUserName);
//			getDistributorApplyListReq.setApplyUserPhone(applyUserPhone);
//			getDistributorApplyListReq.setAuditStatus(auditStatus);
//			getDistributorApplyListReq.setStartTime(startTime);
//			getDistributorApplyListReq.setEndTime(endTime);
			getDistributorApplyListReq.setPageIndex(1);
			getDistributorApplyListReq.setPageSize(10);
			
			getDistributorApplyListCall.setData(getDistributorApplyListReq);
			getDistributorApplyListCall.callService();
			
			Logger.verifyEquals(true, getDistributorApplyListCall.getSuccess(), "验证success");
			
			verifyDb();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
